package com.example.innovate.controller;

import com.example.innovate.bean.Result;
import com.example.innovate.domain.PositionInfoDO;
import com.example.innovate.service.PositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/position")
@Api(tags = "职位信息接口")
public class PositionController {
    @Autowired
    PositionService positionService;

    @PostMapping("/addPosition")
    @ApiOperation("添加职位信息")
    public Result addPosition(@RequestBody PositionInfoDO positionInfoDO) throws Exception{
        positionService.addInfo(positionInfoDO);
        return new Result(200,"success","添加成功",positionInfoDO);
    }

    @DeleteMapping("/deletePosition")
    @ApiOperation("删除职位信息")
    public Result deletePosition(@RequestParam("id") int id) throws Exception{
        PositionInfoDO positionInfoDO = positionService.findById(id);
        if(positionInfoDO!=null){
            positionService.deleteInfo(positionInfoDO.getPoId());
        }
        else{
            return new Result(400,"error","删除信息不存在",null);
        }
        return new Result(200,"success","删除成功",positionInfoDO);
    }

    @PostMapping("/updatePosition")
    @ApiOperation("更新职位信息")
    public Result updatePosition(@RequestBody PositionInfoDO positionInfoDO) throws Exception{
        PositionInfoDO positionInfoDO1 = positionService.findById(positionInfoDO.getPoId());
        if(positionInfoDO1!=null){
            positionService.updateInfo(positionInfoDO);
        }
        else{
            return new Result(400,"error","更新信息不存在",null);
        }
        return new Result(200,"success","更新成功",positionInfoDO);
    }

    @GetMapping("/findPosition")
    @ApiOperation("查找职位信息")
    public Result findPosition(String corporate,String position, String address,
                               @RequestParam double payStart,@RequestParam double payEnd,
                               @RequestParam Integer pageNumber,@RequestParam Integer pageSize
                               ) throws Exception{
        List<PositionInfoDO> list = positionService.findInfo(corporate,position,address,payStart,payEnd,pageNumber,pageSize);
        return new Result(200,"success","查找成功",list);
    }
}
